package com.workcenter.controls;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;

public class CstLinearLayout extends LinearLayout
{

   private AdpCstLinearLayout adapter;
   private OnClickListener onClickListener = null;

   /**
    * 绑定布局
    */
   public void bindLinearLayout()
   {
	  int count = adapter.getCount();
	  for (int i = 0; i < count; i++)
	  {
		 View v = adapter.getView(i, null, null);
		 v.setOnClickListener(this.onClickListener);

		 addView(v, i);
	  }
	  Log.i("DEBUG", "ItemCount" + count);
   }

   public void CleanAllData()
   {
	  if (adapter != null)
	  {
		 adapter = null;
	  }
	  this.removeAllViews();
   }

   public CstLinearLayout(Context context)
   {
	  super(context);
   }

   public CstLinearLayout(Context context, AttributeSet attrs)
   {
	  super(context, attrs);
   }

   /**
    * 获取Adapter
    * 
    * @ return adapter
    */
   public AdpCstLinearLayout getAdapter()
   {
	  return adapter;
   }

   /**
    * 设置数据
    * 
    * @ param adpater
    */
   public void setAdapter(AdpCstLinearLayout adpater)
   {
	  this.adapter = adpater;
	  bindLinearLayout();
   }

   /**
    * 获取点击事件
    * 
    * @ return
    */
   public OnClickListener getCstItemOnClickListener()
   {
	  return onClickListener;
   }

   /**
    * 设置点击事件
    * 
    * @ param onClickListener
    */
   public void setCstItemOnClickListener(OnClickListener onClickListener)
   {
	  this.onClickListener = onClickListener;
   }

   public View getView(int position)
   {
	  return adapter.getView(position, null, null);
   }
}
